$(function () {
    //加载课程数据
    listCourse(1);
    $("body").on('click', '#btn1,#btn2', function () { //搜索课程
        listCourse(1);
    }).on("click",'.openExam',function(){
          var id =  $(this).data("id");
        parent.layer.open({
            type: 2,
            area: winArea,
            btn: ['关闭'],
            content: baseloaction + "/admin/exam/record/examRecordInfo?type=2&examRecordId="+id,
            maxmin: true,
            shade: [0.3, '#000'],
            shadeClose: false,
            title: '查看详情'
        });
    });
    $("#imgUrl").attr("data-original",sessionStorage.getItem("imgUrl"));
    $("#scorePercent").text(sessionStorage.getItem("scorePercent"));
    $("#practiceHeadcount").text(sessionStorage.getItem("practiceHeadcount"));
    $("#practicePassNumber").text(sessionStorage.getItem("practicePassNumber"));
    $("#name").text(sessionStorage.getItem("name"));
    $("#courseName").text(sessionStorage.getItem("courseName"));

    lazyCourseImage();

});

//加载课程数据
function listCourse(page) {
    var params = $("#search-form").serializeJSON();
    params.courseIds=sessionStorage.getItem("courseId");
    params.catalogId=sessionStorage.getItem("catalogId");
    params = JSON.stringify(params);
    var obj = {
        url: baseloaction + '/admin/exam/record/ajaxFindExamRecordPracticeList',//请求URL
        contextId: 'course-list-context',//响应内容页面设置内容ID
        params: params,//请求参数
        pageNo: page,//页码
        pageCall: listCourse, //分页回调加载数据(点击上下页时调用,该方法也在加载页面完成时调用)
        selectAllId: 'all-course', //全选框ID
        callback: function () {//数据加载完成回调
            lazyCourseImage();
           var badge = $(".badge");
           if(badge.length>0){
               for(var i =0;i<badge.length;i++){
                  var accuracy =   $(badge[i]).data("accuracy");
                  var percent=sessionStorage.getItem("percent");
                  if(accuracy>=percent){
                      $(badge[i]).addClass("badge-info").text("通过");
                  }else{
                      $(badge[i]).addClass("badge-danger").text("未通过");
                  }
               }
           }
         var bold = $(".todo");
            if(bold.length>0){
                for(var i =0;i<bold.length;i++){
                  var num = $(bold[i]).data("num");
                    $(bold[i]).text(num.toFixed(2)+"%");
                }
            }

        }
    };
    ajaxGetListData(obj);
}


function lazyCourseImage() {
    //图片数据懒加载
    $('img.lazy').lazyload({
        placeholder: staticPath + '/front/web/v3/img/default/default-course.gif',  //占位图
        effect: 'fadeIn',//载入方式
        threshold: 20, // 提前开始加载
    });
}




